package com.wptk.filemanager.ui.fragment;

import android.view.View;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wptk.filemanager.R;
import com.wptk.filemanager.ad.utils.AnalyticsUtils;
import com.wptk.filemanager.ui.base.BaseFragment;
import com.wptk.filemanager.ui.file.ApkActivity;
import com.wptk.filemanager.ui.file.DocsActivity;
import com.wptk.filemanager.ui.file.DownloadActivity;
import com.wptk.filemanager.ui.file.ImageActivity;
import com.wptk.filemanager.ui.file.MusicActivity;
import com.wptk.filemanager.ui.file.VideoActivity;
import com.wptk.filemanager.utils.StorageQueryUtil;
import com.wptk.filemanager.utils.Utils;

public class FileFragment extends BaseFragment implements View.OnClickListener {


    private RelativeLayout videoRl;
    private RelativeLayout photoRl;
    private RelativeLayout musicRl;
    private RelativeLayout docsRl;
    private RelativeLayout apksRl;
    private RelativeLayout downloadRl;
    private TextView storageInfoTv;
    private ProgressBar pb;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_file;
    }

    @Override
    protected void initView(View rootView) {

        AnalyticsUtils.INSTANCE.logEvent("shiyongql");

        videoRl = rootView.findViewById(R.id.video_rl);
        photoRl = rootView.findViewById(R.id.photo_rl);
        musicRl = rootView.findViewById(R.id.music_rl);
        docsRl = rootView.findViewById(R.id.docs_rl);
        apksRl = rootView.findViewById(R.id.apks_rl);
        downloadRl = rootView.findViewById(R.id.download_rl);

        storageInfoTv = rootView.findViewById(R.id.storage_info_tv);
        pb = rootView.findViewById(R.id.pb);
        String[] result = StorageQueryUtil.queryWithStorageManager(Utils.getContext(), 1024);
        storageInfoTv.setText(result[1]+"/"+result[0]);
        pb.setProgress(Integer.parseInt(result[2]));

    }

    @Override
    protected void initEvent() {

        videoRl.setOnClickListener(this);
        photoRl.setOnClickListener(this);
        musicRl.setOnClickListener(this);
        docsRl.setOnClickListener(this);
        apksRl.setOnClickListener(this);
        downloadRl.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {

        switch (v.getId()){
            case R.id.video_rl:
                migrateTo(VideoActivity.class);
                break;
            case R.id.photo_rl:
                migrateTo(ImageActivity.class);
                break;
            case R.id.music_rl:
                migrateTo(MusicActivity.class);
                break;
            case R.id.docs_rl:
                migrateTo(DocsActivity.class);
                break;
            case R.id.apks_rl:
                migrateTo(ApkActivity.class);
                break;
            case R.id.download_rl:
                migrateTo(DownloadActivity.class);
                break;
        }
    }

}
